package com.ln.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ln.dao.UserDao;
import com.ln.entity.User;
import com.ln.service.UserService;
import com.ln.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/17 15:40
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public Result add(User user) {
        userDao.insert(user);
        Result result = new Result(2000, "添加成功");
        return result;
    }

    @Override
    public Result update(User user) {
        userDao.updateById(user);
        Result result = new Result(2000, "修改成功");
        return result;
    }

    @Override
    public Result delete(int id) {
        userDao.deleteById(id);
        Result result = new Result(2000, "删除成功");
        return result;
    }

    @Override
    public Result select() {
        List<User> users = userDao.selectList(null);
        Result result = new Result(2000, "查询成功", users);
        return result;
    }

    @Override
    public Page<User> selects(int current, int pageSize) {
        Page<User> page = new Page<>(current, pageSize);
        Page<User> userPage = userDao.selectPage(page, null);
        return userPage;
    }
}
